﻿@model List<Carpool1.Models.CarpoolInfo>
@using System.Linq

@{
    ViewBag.Title = "找拼车";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@using Carpool1.Controllers

@if (Model == null || !Model.Any())
{
    <div class="alert alert-info text-center p-5">
        <i class="fa fa-info-circle fs-3"></i>
        <p class="mt-2">@ViewBag.NoResultMessage</p>
    </div>
}
else
{
    <div class="row g-4">
        @foreach (var item in Model)
        {
            var homeCtrl = new HomeController();
            bool isLong = item.InfoType == 1;
            bool isShort = item.InfoType == 2;
        <div class="col-md-6 col-lg-4">
            <div class="card h-100 shadow">
                <div class="card-header bg-primary text-white">
                    <div class="d-flex justify-content-between">
                        <h5 class="mb-0">@item.StartCity → @item.EndCity</h5>
                        <span class="badge @(isLong ? "bg-light text-primary" : "bg-light text-success")">
                            @(isLong ? "长途" : "短途")
                        </span>
                    </div>
                </div>
                <div class="card-body">
                    <p><strong>出发时间：</strong>@item.DepartureTime.ToString("yyyy-MM-dd HH:mm")</p>
                    <p><strong>车型：</strong>@homeCtrl.GetCarTypeText(item.CarType)</p>
                    <p><strong>费用：</strong>
                        @if (item.FeeType == 1)
                        {
                            <span>面议</span>
                        }
                        else
                        {
                            <span>@item.Fee 元/位</span>
                        }
                    </p>
                    <p class="text-muted small">
                        发布于 @item.PublishTime.Value.ToString("MM-dd HH:mm")
                    </p>
                </div>
                <div class="card-footer bg-transparent">
                    <a href="@Url.Action("Detail", "Home", new { id = item.InfoID })" 
                       class="btn btn-outline-primary w-100">
                        查看详情
                    </a>
                </div>
            </div>
        </div>
        }
    </div>
}
